package b.utils.impl

import b.utils.api.T底层Service
import b.utils.entity.C流水号PersistentEntity
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.softwaremill.macwire.wire
import play.api.libs.ws.ahc.AhcWSComponents

/**
  * 贲国称 于 2016/12/20 创建。
  */
abstract class C底层Application(context: LagomApplicationContext) extends LagomApplication(context)
  with AhcWSComponents
  with CassandraPersistenceComponents {

  override lazy val lagomServer: LagomServer = LagomServer.forServices(
    bindService[T底层Service].to(wire[C底层ServiceImpl])
  )

  persistentEntityRegistry.register(wire[C流水号PersistentEntity])

  override lazy val jsonSerializerRegistry: JsonSerializerRegistry = wire[C底层SerializerRegistry]

}

class C底层ApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new C底层Application(context) with LagomDevModeComponents

  override def load(context: LagomApplicationContext): LagomApplication = new C底层Application(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
  }
}
